#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>

void runChild(){
  int cnt = 2;
  while(cnt--){
    printf("I am Child, pid:%d, ppid:%d\n",getpid(),getppid());
    sleep(1);
  }
}


int main(){
  pid_t pid = fork();
  if(pid == 0){
    runChild();
    exit(11);
  }
//  int cnt = 10;
//  while(cnt--){
//    printf("I am Father, pid:%d, ppid:%d\n",getpid(),getppid());
//    sleep(1);
//  }
  int status = 0;
  while(1){
       pid_t ret = waitpid(pid,&status,WNOHANG);
       if(ret>0){
         printf("success wait %d ,exit_code:%d , exit_signal:%d\n",ret,(status>>8)&0xff,status&0x7f);
         break;
       }else if(ret<0){
         printf("not success wait %d\n",ret);
         break;
       }else{
         printf("轮询等待中!!!!\n");
       }
  }
  sleep(5);
  return 0;
}
